package com.hongning.railway.ui.main.fragments.college.itemviewModel;

import android.databinding.ObservableField;
import android.databinding.ObservableInt;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;

import com.hongning.railway.R;
import com.hongning.railway.app.Constant;
import com.hongning.railway.entity.resbean.ResVideoBean;
import com.hongning.railway.ui.categorylistnews.NewDetailFragment;
import com.hongning.railway.ui.webview.AppWebViewFragment;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class LessonItemViewModel extends MultiItemViewModel {
    public ObservableField<ResVideoBean> videoData = new ObservableField<>();
    public ObservableField<String> statu = new ObservableField<>();
    public ObservableInt statucolor = new ObservableInt();
    public ObservableInt descvisiable = new ObservableInt();
    public BindingCommand onItemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (videoData.get().getNewsCategory()==1){
                Bundle bundle = new Bundle();
                bundle.putParcelable(NewDetailFragment.NEWS_INFO,videoData.get());
                viewModel.startContainerActivity(NewDetailFragment.class.getCanonicalName(),bundle);
            }else if (videoData.get().getNewsCategory()==3){
                Bundle bundle = new Bundle();
                bundle.putString(Constant.EXTRA_TITLE,"课程详情");
                bundle.putString(Constant.EXTRA_ID,videoData.get().getNewsId());
                bundle.putString(Constant.EXTRA_STRING,videoData.get().getNewsContent());

                viewModel.startContainerActivity(AppWebViewFragment.class.getCanonicalName(),bundle);
            }

        }
    });
    public LessonItemViewModel(@NonNull BaseViewModel viewModel, ResVideoBean resVideoBean,Boolean isComplete) {
        super(viewModel);
        multiItemType(resVideoBean.getType());
        videoData.set(resVideoBean);
        if (TextUtils.isEmpty(resVideoBean.getNewsRoundup())){
            descvisiable.set(View.GONE);
        }else {
            descvisiable.set(View.VISIBLE);
        }
        if (isComplete){
            statu.set("已完成");
            statucolor.set(viewModel.getApplication().getResources().getColor(R.color.color_9D9D9D));
        }else {
            statu.set("未完成");
            statucolor.set(viewModel.getApplication().getResources().getColor(R.color.colorPrimary));
        }
    }
}
